/*匹配日期 */
var regex=/\d{4}-0[1-9]|1[1-2]-0[1-9]|[1-2][0-9]|3[0-1]/
console.log( regex.test("2017-06-10") ); 

/*window操作系统文件路径 */
 regex = /^[a-zA-Z]:\\([^\\:*<>|"?\r\n/]+\\)*([^\\:*<>|"?\r\n/]+)?$/;
 console.log( regex.test("F:\\study\\javascript\\regex\\regular expression.pdf") ); 
console.log( regex.test("F:\\study\\javascript\\regex\\") ); 
console.log( regex.test("F:\\study\\javascript") ); 
console.log( regex.test("F:\\") ); 

/*匹配id */
var regex = /id="[^"]*"/
var string = '<div id="container" class="main"></div>';
console.log(string.match(regex)[0]); 

var result = "hello".replace(/^|$/g, '#');
console.log(result); 
// => "#hello#"

var result = "I\nlove\njavascript".replace(/^|$/gm, '#');
console.log(result);
/*
#I#
#love#
#javascript#
*/

/**\b为\w和\W之间 */
var result = "[JS] Lesson_01.mp4".replace(/\b/g, '#');
console.log(result); 
// => "[#JS#] #Lesson_01#.#mp4#"
/*[#JS#] #Lesson_01#.#mp4#  */

var result = "[JS] Lesson_01.mp4".replace(/\B/g, '#');
console.log(result); 
// => "#[J#S]# L#e#s#s#o#n#_#0#1.m#p#4"
/* #[J#S]# L#e#s#s#o#n#_#0#1.m#p#4 */

/*(?=l)，表示'l'字符前面的位置 */
var result = "hello".replace(/(?=l)/g, '#');
console.log(result); 
// => "he#l#lo"

var result = "hello".replace(/(?!l)/g, '#');
console.log(result); 
// => "#h#ell#o#"

var result = /(?=he)^^he(?=\w)llo$\b\b$/.test("hello");
console.log(result); 
// => true

var result = "12345678".replace(/(?=\d{3}$)/g, ',')
console.log(result); 
// => "12345,678"

var result = "123456789".replace(/(?=(\d{3})+$)/g, ',')
console.log(result); 
// => "12,345,678"

/* var result="123456789".match(/(?=(\d{3})+$)/g)
console.log(result);  */

var string1 = "12345678",
string2 = "123456789";
reg = /(?!^)(?=(\d{3})+$)/g;
result = string2.replace(reg, ',');
console.log(result); 
// => "123,456,789"

var string = "12345678 123456789",
reg = /(?!\b)(?=(\d{3})+\b)/g;
var result = string.replace(reg, ',')
console.log(result); 
// => "12,345,678 123,456,789"








